/**
 * Created by Administrator on 2015/6/15.
 */
var urlUtil =  require("url");
exports.requestOption=function(pageLink,method,referer){
    var urlobj = urlUtil.parse(pageLink);
    var __host = urlobj['hostname'];
    var __port = urlobj['port'];
    var __path = urlobj['path'];
    var options = {
        'host': __host,
        'port': __port,
        'path': __path,
        'method': method,
        'headers': {
            "User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.18 Safari/537.36",
            "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
            "Accept-Encoding":"gzip, deflate, sdch",
            "Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4",
            "Referer":referer===undefined?pageLink:referer
        }
    };
    return options;
};
exports.get_page_encoding = function(header){
    var page_encoding = 'UTF-8'
    if(header['content-type']!=undefined){
        var contentType = header['content-type'];
        var patt = new RegExp("^.*?charset\=(.+)$","ig");
        var mts = patt.exec(contentType);
        if (mts != null)
        {
            page_encoding = mts[1];
        }
    }
    return page_encoding;
};
